package net.alteiar.images.filter;

import java.awt.Color;
import java.util.ArrayList;
import java.util.List;

import net.alteiar.Array2D;
import net.alteiar.images.metadata.IImageInfo;
import net.alteiar.images.metadata.VisionInfo;

public class VisionFilter extends BasicFilter {
	private static Color HIDDEN_DEFAULT = new Color(0f, 0f, 0f, 0.8f);
	private static Color VISIBLE_DEFAULT = new Color(0f, 0f, 0f, 0f);

	private final List<VisionInfo> vision;

	public VisionFilter(IImageInfo img) {
		this(img, HIDDEN_DEFAULT, VISIBLE_DEFAULT);
	}

	public VisionFilter(IImageInfo info, Color hidden, Color visible) {
		super(info);

		vision = new ArrayList<>();

		updateFilter();
	}

	public void addVision(VisionInfo builder) {
		vision.add(builder);
		builder.addObserver(this);
		updateFilter();
	}

	@Override
	protected void updateFilter() {
		Array2D image = getImageArray2D();
		image.fill(HIDDEN_DEFAULT.getRGB());

		for (VisionInfo builder : vision) {
			builder.computeVision(image, VISIBLE_DEFAULT.getRGB(),
					HIDDEN_DEFAULT.getRGB());
		}
	}
}
